﻿/*
{
"状态":1,
"名称":"新增-字典信息",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"新增-字典信息",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @dict_key varchar(100),@detail_name varchar(100),@dict_id varchar(100)

set @dict_key = '{dict_key}'
set @detail_name = '{detail_name}'
set @dict_id = '{dict_id}'

--校验信息
if isnull(@dict_id,'')=''
begin 
	RAISERROR ('SQL:字典id不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@detail_name,'')=''
begin 
	RAISERROR ('SQL:字典名称不允许为空', 16 ,1 ) ; 
	return 
end 

if not @dict_id like @dict_key+'%'
begin
	RAISERROR ('SQL:字典id,请按字典key+流水号格式', 16 ,1 ) ; 
	return 
end  

if EXISTS(SELECT * FROM y_dict WHERE dict_id=@dict_id )
begin
	RAISERROR ('SQL:字典id已经存在', 16 ,1 ) ; 
	return 
end

if EXISTS(SELECT * FROM y_dict WHERE [dict_key]=@dict_key and detail_name=@detail_name)
begin
	RAISERROR ('SQL:字典名称已经存在', 16 ,1 ) ; 
	return 
end


INSERT INTO [dbo].[y_dict]([dict_id],[dict_key],[detail_name],[create_time],[update_time])
VALUES( @dict_id , @dict_key  , @detail_name , getdate(), getdate() )

